﻿#ifndef _REC_WRITE_H_
#define _REC_WRITE_H_

#include "rec_info.h"
#include "rec_write_base.h"

class CRecordWriter:public CRecWriteBase
{
public:
    CRecordWriter(int channel =0);
    ~CRecordWriter();
    virtual int Open(const char * dev, uint32_t fileIndex, uint32_t fileSize,int64_t startTime = 0,PSTFS_RECINFO_EXTERN pExternInfo = NULL);
    virtual int OpenRepairFile(REC_FILE_INFO & recInfo,uint32_t fileLen,int64_t startTime = 0); //追加写入修复的文件,节省空间.
    virtual int SaveSpsPps(uchar_t * data_buf, uint32_t data_size);
	int Close();

    //写入单帧数据
    virtual int WriteFrame(uchar_t * frameBuf, uint32_t dataSize);

	virtual int RepairFile(char*  diskName,uint32_t fileIndex,uint64_t fileLBA,uint32_t recSize,int64_t startTime,uint32_t& fileSize,int64_t & endTime);

	//合并上一段录像
	void MergeRec(REC_FILE_INFO & recordInfo);

	int IdentifyData(STFS_REC_IDX recIdx);

	static int  ClearFile(char*  diskName,uint32_t fileIndex,uint32_t fileSize,int64_t startTime = 0,int64_t endTime = 0);
	static void CreateRecIdxSize(uint32_t & idxLen,int frameSize,int fsHdLen);
	virtual uint32_t GetWritePercent()
	{
		return (uint32_t)((float)m_curPos*100/(float)m_fileHead.fileSpace);
	}
protected:

	bool IsContextCreateIdx(int frmType, int64_t time);
};


#endif //_REC_WRITE_H_
